<template>
  <div>
    <interview-user-interview-card
      style="margin-top: 20px"
      :form="form"
      :eduexp="eduexp"
      :workexp="workexp"
      :type="1"
      :depname="depname"
      :selectdepartment="selectdepartment"
      :selectpost="selectpost"
    >
    </interview-user-interview-card>

    <el-container>
      <el-main>
        <interview-user-comment
          :commentdata="commentdata"
        ></interview-user-comment> </el-main
    ></el-container>

    <el-container>
      <el-main>
        <el-card
          class="box-card"
          shadow="hover"
          style="background-color: #fafafa"
        >
          <div slot="header" class="clearfix">
            <span style="font-weight: bold">我的评价</span>
            <el-tag style="float: right">{{ username }}</el-tag>
          </div>

          <el-form
            label-position="top"
            :model="comment"
            :rules="rules"
            ref="ruleForm"
          >
            <el-form-item style="margin-top: -10px" prop="score">
              <span class="demonstration">面试评分</span>
              <el-rate v-model="comment.score" show-text> </el-rate>
            </el-form-item>
            <el-form-item
              label="面试结果"
              style="margin-top: -10px"
              prop="isagree"
            >
              <el-select v-model="comment.isagree">
                <el-option label="同意" value="同意"></el-option>
                <el-option label="不同意" value="不同意"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item style="margin-top: -10px" prop="comment">
              <span class="demonstration">面试意见</span>
              <el-input
                type="textarea"
                :autosize="{ minRows: 3, maxRows: 4 }"
                v-model="comment.comment"
              ></el-input>
            </el-form-item>

            <el-form-item>
              <el-button
                type="primary"
                @click="postcomment('ruleForm')"
                style="width: 100%"
                >提交</el-button
              >
            </el-form-item>
          </el-form>
        </el-card>
      </el-main>
    </el-container>
    <el-container v-if="showsalary == 0" style="margin-top: -70px"
      ><el-main>
        <el-descriptions class="margin-top" size="medium" :column="2" border>
          <el-descriptions-item
            :span="2"
            :contentStyle="{ 'text-align': 'center' }"
            :labelStyle="{ 'text-align': 'center' }"
          >
            <template slot="label">
              <i class="el-icon-tickets"></i>
              终定薪酬(￥)
            </template>
            <el-input
              v-model="form.salary"
              style="width: 100%"

            ></el-input>
          </el-descriptions-item>

          <el-descriptions-item
            :span="2"
            :contentStyle="{ 'text-align': 'center' }"
            :labelStyle="{ 'text-align': 'center' }"
          >
            <template slot="label">
              <i class="el-icon-location-outline"></i>
              入职日期
            </template>
            <el-date-picker
              v-model="form.employdate"
              style="width: 100%"
              type="date"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd"
            ></el-date-picker
            >
          </el-descriptions-item>

          <el-descriptions-item
            :span="2"
            :contentStyle="{ 'text-align': 'center' }"
            :labelStyle="{ 'text-align': 'center' }"
          >
            <template slot="label">
              <i class="el-icon-location-outline"></i>
              平均分数
            </template>
            <el-rate v-model="score" disabled show-score text-color="#ff9900">
            </el-rate>
          </el-descriptions-item>
        </el-descriptions>
      </el-main>
    </el-container>
    <!-- <el-container v-if="(showsalary == 0) & showagree"
      ><el-main>
        <el-button-group style="width: 100%">
          <el-button type="success" style="width: 50%" @click="postagree"
            >同意</el-button
          >
          <el-button type="danger" style="width: 50%" @click="postdisagree"
            >不同意</el-button
          >
        </el-button-group>
      </el-main>
    </el-container> -->
  </div>
</template>

  <script>
import InterviewUserComment from "../InterviewUser/InterviewUserComment.vue";
import InterviewUserInterviewCard from "../InterviewUser/InterviewUserInterviewCard.vue";

export default {
  components: {
    InterviewUserInterviewCard,
    InterviewUserComment,
  },
  async created() {
    this.getUrlKey();

    this.getUserDetail();

    this.getComment();

    if (this.showsalary == 0) {
      this.getinterviewscore();
    }
  },

  data() {
    return {
      showsalary: "",

      showpost: true,

      showagree: true,

      username: "",

      posterid: "",

      commentdata: [],

      interviewid: "",
      userid: "",

      eduexp: [],
      workexp: [],
      form: {},
      depname: "",

      comment: [],

      rules: {
        score: [{ required: true, message: "请打分", trigger: "change" }],
        isagree: [
          { required: true, message: "请选择面试结果", trigger: "change" },
        ],
        comment: [{ required: true, message: "请给出评价", trigger: "blur" }],
      },
    };
  },
  methods: {
    async getinterviewscore() {
      let comment = await this.$axios.get(
        `api/interview/getinterviewscore?id=` + this.interviewid
      );
      this.score = comment.data;
    },

    searchcomment() {
      this.commentdata.forEach((item) => {
        if (item.userid == this.userid) {
          this.showpost = false;
        }
      });
    },

    /* 获取地址栏url参数 */
    getUrlKey() {
      var url = window.location.href; //获取当前url
      this.nowurl = url;
      var dz_url = url.split("#")[0]; //获取#/之前的字符串
      var cs = dz_url.split("?")[1]; //获取?之后的参数字符串
      var cs_arr = cs.split("&"); //参数字符串分割为数组
      var cs = {};
      for (var i = 0; i < cs_arr.length; i++) {
        //遍历数组，拿到json对象
        cs[cs_arr[i].split("=")[0]] = cs_arr[i].split("=")[1];
      }
      this.interviewid = cs.id;
      this.userid = cs.userid;
      this.posterid = cs.posterid;
      this.showsalary = cs.showsalary;
      this.score = cs.avg;
      // this.salary = cs.salary;
      // this.date = cs.date;
      if (cs.status == "3") {
        this.agree = false;
      }
    },

    async getComment() {
      let id = this.interviewid;
      let comment = await this.$axios.get(
        `api/interview/getinterviewcomment?id=` + id
      );
      this.commentdata = comment.data;
      this.searchcomment();
    },

    async getUserDetail() {
      let id = this.interviewid;
      let userid = this.userid;
      try {
        let res = await this.$axios.get(`api/member/getuserdetail?id=` + id);
        this.form = res.data.member[0];
        this.eduexp = res.data.eduexp;
        this.workexp = res.data.workexp;
        if (this.form.status == 3) {
          this.showagree = false;
        }

        let name = await this.$axios.get(
          "api/member/getuserinfobyuserid?userid=" + userid
        );
        this.username = name.data;

        let dep = await this.$axios.get(
          `api/member/getdepname?id=` + res.data.member[0].depid
        );
        this.depname = dep.data;
      } catch (e) {}
    },

    async postcomment(formName) {
      this.$confirm("确认提交面试结果?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.$refs[formName].validate((valid) => {
            if (valid) {
              let datas = {
                interviewid: this.interviewid,
                userid: this.userid,
                isagree: this.comment.isagree,
                posterid: this.posterid,
                comment: this.comment.comment,
                score: this.comment.score,
                username: this.username,
                interviewname: this.form.name,
                employdate:this.form.employdate,
                salary:this.form.salary,
              };

              this.$axios
                .post("api/interview/postinterviewcomment", datas)
                .then((response) => {
                  this.$router.push("/success");
                  // this.$message({
                  //   message: response.data,
                  //   type: "success",
                  // });
              
               
                })
                .catch(function (error) {
                  console.log(error);
                });
            } else {
              console.log("error submit!!");
              return false;
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
  },
};
</script>

  <style lang="scss" scoped>
</style>
